<?php

namespace App\Listeners;

use App\Models\Java\PdUserRelationship;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Http;

class UpdateUserListener implements ShouldQueue
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  object  $event
     * @return void
     */
    public function handle($event)
    {
        $data = $event->order;
        info('更新了用数据'.json_encode($data));
        if($data->openid){
            $user =  PdUserRelationship::query()->where('uid',$data->openid)
                ->where('role',3)->first();
            if($user){
                $user->name = $data->name;
                $user->avatar = $data->avatar;
                $user->mobile = $data->wx_phone;
                $user->save();
            }
        }

        // 设置农道用户openid
//        $this->setNdUser($data);
        //$response = Http::post(env('COMMISSION_URL').'/pay_divide/batchUpdateUserInfo/', []);
        //$last = $response->body();
        //$result = json_decode($last,true);
//        if($result){
//            info('获取更新用户回调',$result);
//        }
    }
    public function setNdUser($response){

        $response = Http::post(env('ND_API_URL').'/api/Login/setRemoteUser/', ['openid'=>$response['openid']]);
        $last = $response->body();
        $result = json_decode($last,true);
    }
}
